def _link_impl(ctx):
    exec_file = ctx.outputs.exec_file

    args = ctx.actions.args()
    args.add_all(ctx.files.libs)

    args.add("-o")
    args.add(exec_file)
    args.add("-B")
    args.add("/usr/bin")

    ctx.actions.run(
        executable = "/usr/bin/g++",
        arguments  = [args],
        inputs     = ctx.files.libs,
        outputs    = [exec_file],
    )

    return [DefaultInfo(files = depset([exec_file]))]


link = rule (
    implementation = _link_impl,
    attrs = {
        "libs" : attr.label_list(
            allow_files = True,
            doc = "input obj files",
        ),
        "exec_file" : attr.output(),      # 最后的可执行文件
    },
    executable = False,
    test       = False,
)